﻿@{
    ViewBag.Title = "用户登录";
    Layout = "~/Views/Shared/_UserLayout.cshtml";
}

<div class="layui-container fly-marginTop">
    <div class="fly-panel fly-panel-user" pad20>
        <div class="layui-tab layui-tab-brief" lay-filter="user">
            <ul class="layui-tab-title">
                <li class="layui-this">登入</li>
                <li><a href="reg.html">注册</a></li>
            </ul>
            <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                <div class="layui-tab-item layui-show">
                    <div class="layui-form layui-form-pane">
                        <form method="post" class="layui-form">
                            <div class="layui-form-item">
                                <label for="L_email" class="layui-form-label">邮箱</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_email" name="email" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_pass" class="layui-form-label">密码</label>
                                <div class="layui-input-inline">
                                    <input type="password" id="L_pass" name="userpwd" required lay-verify="required" autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_vercode" class="layui-form-label">人类验证</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_vercode" name="vercode" required lay-verify="required" placeholder="请回答后面的问题" autocomplete="off" class="layui-input">
                                </div>
                                <div class="layui-form-mid">
                                    <img id="valiCode" src="@Url.Action("GetValidateCode", "Common")" style="cursor:pointer;" alt="验证码" />
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <button class="layui-btn" lay-filter="login" lay-submit>立即登录</button>
                                <span style="padding-left:20px;">
                                    <a href="forget.html">忘记密码？</a>
                                </span>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script>
        layui.config({
            base: "~/Content/res/mods/"
        }).use(['layer','form'], function () {
            var layer = layui.layer,
                form = layui.form,
                $ = layui.jquery
                

            form.on('submit(login)', function (data) {
                $.post('@Url.Action("Login","User")', data.field, function (data) {
                    if (data.code == 0) {
                        window.location.href = '@Url.Action("Index","Home")';
                    }
                    else
                    {
                        layer.msg(data.msg, { icon: 2 });
                        $("img[id=valiCode]").click();
                    }

                }, "json");
                return false;
            })
            //刷新验证码
            $("img[id=valiCode]").on("click", function () {
                this.src = '@Url.Action("GetValidateCode", "Common")?v=' + new Date().getTime();
            })
        });

        //登录成功之后
        //function funcLoginSuccess(data) {
        //    if (data == "ok") {
        //        window.location.href = "/Home/Index";
        //    }
        //    else {
        //        layer.alter(data);
        //    }
        //}
    </script>
}
